<?php
namespace Plu\Library\Models\Platform\Music;

use Phalcon\Mvc\Model,
    Phalcon\Db\Column;

class LiveSession extends Model {
    public $id;

    public $Status;

    public $RoomId;

    public $Name;

    public $Guest;

    public $Percentage;

    public $Contribution;

    public $Start;

    public $End;

    public $BindRoomId;

    public function initialize() {
        $this->setReadConnectionService('db.platform.slave');
    }

    public function getSource() {
        return "LiveSession";
    }

    /**
     * 根据时间范围获取房间的收入
     */
    static public function getRoomsContributionByDate($starttime, $endtime, $offset = 0, $limit = 10) {
        $group = self::sum(array(
            'conditions' => 'Start >= :starttime: AND Start < :endtime: AND BindRoomId > 0',
            'column' => 'Contribution',
            'group'  => 'BindRoomId',
            "order"  => "sumatory DESC",//根据收入数据进行一个倒序排序
            'bind'   => array(
                'starttime' => $starttime,
                'endtime'   => $endtime
            ),
            "offset" => $offset,
            "limit"  => $limit
        ));

        return $group->toArray();
    }
}

?>
